
#include <cegfx/cematerial.h>
#include <cegfx/cegeometrynode.h>
#include <cegfx/igeometry.h>
#include <cegfx/igeometryanimator.h>

ceGeometryNode::ceGeometryNode ()
	: ceNode (NT_GeometryNode)
	, geometry (0)
	, material (0)
	, animator (0)
	, transparency (false)
{
	IQF_CONSTRUCT;
}

ceGeometryNode::~ceGeometryNode ()
{
	SAVE_RELEASE(geometry);
	SAVE_RELEASE(material);
}


IQF_IMPLEMENTATION_BEGIN(ceGeometryNode);
IQF_IMPLEMENTATION_END ();

void ceGeometryNode::SetGeometry(iGeometry* geometry)
{
	SAVE_SET(this->geometry, geometry);
}

iGeometry* ceGeometryNode::GetGeometry()
{
	return geometry;
}

const iGeometry* ceGeometryNode::GetGeometry () const
{
	return geometry;
}

void ceGeometryNode::SetMaterial (ceMaterial* material)
{
	SAVE_SET(this->material, material);
}

ceMaterial* ceGeometryNode::GetMaterial ()
{
	return material;
}

const ceMaterial* ceGeometryNode::GetMaterial () const
{
	return material;
}


void ceGeometryNode::SetGeometryAnimator (iGeometryAnimator* animator)
{
	SAVE_SET(this->animator, animator);
}

iGeometryAnimator* ceGeometryNode::GetGeometryAnimator ()
{
	return animator;
}

const iGeometryAnimator* ceGeometryNode::GetGeometryAnimator () const
{
	return animator;
}

void ceGeometryNode::SetTransparency (bool transparency)
{
	this->transparency = transparency;
}

bool ceGeometryNode::HasTransparency () const
{
	return transparency;
}

void ceGeometryNode::Update (const ceUpdateEnv& env)
{
	ceNode::Update (env);
	if (geometry)
	{
		geometry->Update (env);
	}
}

void ceGeometryNode::UpdateBoundingBox ()
{
	UpdateBoundingBox (&GetTransform().GetMatrix (), &GetBoundingBox());
}

void ceGeometryNode::UpdateBoundingBox (D3DXMATRIX* matrix, ceBoundingBox* bbox)
{
	if (geometry)
	{
		geometry->GetBoundingBox ().Transform (matrix, bbox);
	}
}

